<template>
	<page-meta>
		<navigation-bar title="乐居" background-color="#354e44" />
	</page-meta>
	<view class="modify">
		<view class="modify-modify">
			<view class="modify-modify-btn">修改用户信息</view>
		</view>
		<view class="modify-info">
			<view class="modify-info-label">头像</view>
			<view @tap="chooseImage" v-if="!icon.length" class="modify-info-btn">上传头像</view>
			<image class="modify-info-img" v-else :src="icon"></image>
		</view>
		<view class="modify-info">
			<view class="modify-info-label">用户名</view>
		</view>
		<view class="modify-info">
			<view class="modify-info-label">昵称</view>
			<view class="modify-info-desc">{{userInfo.nickname}}</view>
		</view>
		<view class="modify-info">
			<view class="modify-info-label">手机号</view>
			<input v-model="phone" class="modify-info-input" type="text" placeholder="请输入手机号" />
		</view>
		<view @tap="update" class="modify-update">
			更新
		</view>
	</view>
</template>

<script>
	import baseUrl from '../../../api/baseUrl.js'
	import  {updateMemberInfo as updateMemberInfoApi} from '../../../api/user/index.js'
	export default {
		data() {
			return {
				userInfo: {},
				icon: '',
				phone:''
			}
		},
		onLoad() {
			this.userInfo = uni.getStorageSync('userInfo');
			console.log('用户信息==>', this.userInfo);
		},
		methods: {
			//更新信息
			update(){
				updateMemberInfoApi({
					  "birthday": "2022-07-27 01:18:37",
					  "city": "郑州市",
					  "email": "1050879576@qq.com",
					  "icon": this.icon,
					  "id": this.userInfo.id,
					  "nickname": this.userInfo.nickname,
					  "personalizedSignature": "渊远流长",
					  "phone":this.phone,
					  "sex": 0
				})
				.then(res=>{
					uni.navigateTo({
						url:'../login/login'
					})
				})
			},
			//上传头像
			chooseImage() {
				var _this = this;
				uni.chooseImage({
					count: 1,
					success(res) {
						console.log('上传头像', res);
						var img = res.tempFilePaths[0];
						uni.uploadFile({
							name: 'file',
							filePath: img,
							url: baseUrl + '/lejuClient/orderReturn/uploadImg',
							timeout: 5000,
							success(res) {
								console.log('图像上传', res);
								_this.icon = JSON.parse(res.data).data.fileUrl;
							}
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.modify {
		width: 100%;
		height: 100%;
		min-height: 100vh;
		background-color: #f1ece7;
		padding: 30rpx;
		box-sizing: border-box;

		&-modify {
			display: flex;
			justify-content: flex-end;

			&-btn {
				width: 250rpx;
				height: 70rpx;
				border-radius: 15rpx;
				line-height: 70rpx;
				border: 1rpx solid #333333;
				text-align: center;
			}
		}

		&-info {
			display: flex;
			justify-content: space-between;
			align-items: center;
			line-height: 100rpx;
			padding: 10rpx;
			border-bottom: 1rpx solid #ddd;

			&-img {
				display: block;
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
			}

			&-btn {
				border: 1rpx solid #333333;
				line-height: 60rpx;
				padding: 0 10rpx;
				border-radius: 10rpx;
			}

			&-input {
				text-align: right;
			}

		}

		&-update {
			width: 370rpx;
			height: 88rpx;
			background-color: #1c4b47;
			color: #FFFFFF;
			text-align: center;
			line-height: 88rpx;
			border-radius: 20rpx;
			margin: 200rpx auto 0;
		}
	}
</style>
